// 将wx.request 封装支持Promise语法
import {ID,KEY,BASE} from '../config/index'
function $http(url,method="GET",data={}){
    return new Promise((resolve,reject)=>{
        wx.request({
            url: `${BASE}/1.1/${url}`,
            header:{
              "X-LC-Id": ID,
              "X-LC-Key": KEY,
              "Content-Type": "application/json"
            },
            method,
            data,
            success:(res)=>{
                resolve(res)  //提供给then
            },
            fail:(err)=>{
                reject(err)  //提供给catch
            }
        })
    })
}

function $get(url,data){
    return $http(url,'GET',data)
}
function $post(url,data){
    return $http(url,'POST',data)
}

export {
    $http,
    $get,
    $post
}
// $http('classes/ReactBanner').then(res).catch()